import Vue from 'vue'

export default {
  
  create(data) {
    return new Promise((resolve, reject) => {
      Vue.axios.post('/user', data).then(response => {
        resolve(response.data)
      })
    })
  },
  
  delete(id) {
    return new Promise((resolve, reject) => {
      Vue.axios.delete('/user/' + id).then(response => {
        resolve(response.data)
      })
    })
  },
  
  deleteTag(id, tag_id) {
    return new Promise((resolve, reject) => {
      Vue.axios.delete('/user/' + id, {params: {tag_id: tag_id}}).then(response => {
        resolve(response.data)
      })
    })
  },
  
  addTag(data) {
    return new Promise((resolve, reject) => {
      Vue.axios.post('/user', data).then(response => {
        resolve(response.data)
      })
    })
  },
  
  getList(map) {
    return new Promise((resolve, reject) => {
      Vue.axios.get('/user', {params: map}).then(response => {
        resolve(response.data)
      })
    })
  },
  
  getInfo(id, map = {}) {
    //查询参数可以指定member=1查询会员信息，而不是用户本身的信息
    return new Promise((resolve, reject) => {
      Vue.axios.get('/user/' + id, {params: map}).then(response => {
        resolve(response.data)
      })
    })
  },
  
  getMemberInfo(uid) {
    //查询参数可以指定member=1查询会员信息，而不是用户本身的信息
    return new Promise((resolve, reject) => {
      Vue.axios.get('/user/' + uid, {params: {member: 1}}).then(response => {
        resolve(response.data)
      })
    })
  },
  
  getInfoByName(userName) {
    return new Promise((resolve, reject) => {
      Vue.axios.get('/user', {params: {username: userName}}).then(response => {
        resolve(response.data)
      })
    })
  },
  
  
  //更新用户基本信息
  update(id, data) {
    return new Promise((resolve, reject) => {
      Vue.axios.put('/user/' + id, data).then(response => {
        resolve(response.data)
      })
    })
  },
  
  //更新user_member信息
  updateMemberInfo(uid, data) {
    return new Promise((resolve, reject) => {
      Vue.axios.put('/user/' + uid + '?member=1', data).then(response => {
        resolve(response.data)
      })
    })
  }
}
